package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.JsonResponseCode;
import com.tt.fashionWebSite.dto.JsonResponseDto;
import com.tt.fashionWebSite.dto.LoaiDanhMucDto;
import com.tt.fashionWebSite.dto.MauSacDto;
import com.tt.fashionWebSite.service.Ad_ProductListCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_ProductListCategoryController {
    @Autowired
    private Ad_ProductListCategoryService ad_productListCategoryService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adProductListCategory", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminProductListCategory(HttpServletRequest request, @RequestBody LoaiDanhMucDto productListCategoryDto) {
        return new JsonResponseDto<Integer>(ad_productListCategoryService.adminProductListCategory(productListCategoryDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adProductListCategoryDelete", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminProductListCategoryDelete(HttpServletRequest request, @RequestBody List<LoaiDanhMucDto> productListCategoryDto) {
        return new JsonResponseDto<Integer>(ad_productListCategoryService.adminProductListCategoryDelete(productListCategoryDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllListCategory", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<LoaiDanhMucDto>> getAllListCategory(HttpServletRequest request) {
        return new JsonResponseDto<List<LoaiDanhMucDto>>(ad_productListCategoryService.getAllListCategory(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductListCategoryPage/{maLoai}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageListCategory(HttpServletRequest request, @PathVariable String maLoai, Map<String, Object> map) throws ParseException {
        map.put("maLoai", maLoai);
        return new ModelAndView("admin/ad-product-listcategory-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editProductListCategory", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<LoaiDanhMucDto> getListCategoryInfoEdit(HttpServletRequest request, @RequestBody LoaiDanhMucDto categoryDto) {
        return new JsonResponseDto<LoaiDanhMucDto>(ad_productListCategoryService.getListCategoryInfoEdit(categoryDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerListCategoryEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<LoaiDanhMucDto> registerListCategoryEdit(HttpServletRequest request, @RequestBody LoaiDanhMucDto categoryDto) {
        return new JsonResponseDto<LoaiDanhMucDto>(ad_productListCategoryService.registerListCategoryEdit(categoryDto), JsonResponseCode.SUCCESS);
    }
}